<template>
  <div class="todo-footer" v-show="todoList.length">
        <label>
          <!-- <input type="checkbox" :checked="checkAll"  @change="checkAllBoc"/> -->
          <input type="checkbox" v-model="checkAll"/>
        </label>
        <span>
          <span>已完成{{golTatol}}</span> / 全部{{todoList.length}}
        </span>
        <button class="btn btn-danger" @click="clearAll">清除已完成任务</button>
      </div>
</template>

<script>
export default {
  props: ['todoList', 'checkTodo', 'clearAlltodo'],
  computed: {
    golTatol () {
      // return this.todoList.reduce((val, pre) => {
      //   // 判断如果里面值经过判断合格就加，不然不加
      //   return val + (pre.done ? 1 : 0)
      // }, 0)
      return this.todoList.reduce((pre, todo) => pre + (todo.done ? 1 : 0), 0)
    },
    checkAll: {
      get () {
        return this.golTatol === this.todoList.length && this.golTatol > 0
      },
      set (value) {
        return this.checkTodo(value)
      }
    }
  },
  methods: {
    // 清除完成
    clearAll () {
      // 这里就直接调用就可以取得到
      this.clearAlltodo()
    },
    checkAllBoc (e) {
      // 拿到是否全部勾选或者全部不勾选的指令
      return this.checkTodo(e.target.checked)
    }
  }
}
</script>

<style>
/*footer*/
.todo-footer {
  height: 40px;
  line-height: 40px;
  padding-left: 6px;
  margin-top: 5px;
}

.todo-footer label {
  display: inline-block;
  margin-right: 20px;
  cursor: pointer;
}

.todo-footer label input {
  position: relative;
  top: -1px;
  vertical-align: middle;
  margin-right: 5px;
}

.todo-footer button {
  float: right;
  margin-top: 5px;
}
</style>
